package com.noahplat.user.mapper;

import com.noahplat.user.pojo.UserRole;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

import java.util.Set;

/**
 * 用户权限中间表关系映射
 *
 * @author 李东
 * @version 1.0.0
 * @Date: 2021/2/27 8:56
 **/
public interface UserRoleMapper extends Mapper<UserRole> {
    @Update("update tb_user_role set uid = #{uid},rid = #{newrid} where uid = #{uid} and rid = #{oldrid}")
    int updateUserRole(@Param("uid") Long uid, @Param("newrid") Long newrid, @Param("oldrid") Long oldrid);

    @Insert("<script> INSERT INTO tb_user_role(uid,rid) VALUES <foreach collection = 'newrid' item='record' separator=','>" +
            "(#{uid},#{record})</foreach></script>")
    int insertUserRole( @Param("uid") Long uid,@Param("newrid") Set<Long> newrid);
}
